import { HomePageService } from './../home/index';
import { expeditionOrdersService } from './../../services/expeditionOrders';
import { GrowlMessageType } from './../../components/messageBox/growMeaageType';
import { MessageBoxService } from './../../components/messageBox/messageBoxService';
import { NavigateManage } from './../../common/navigateManage';
import { LocalstorageDataManage } from './../../common/localstoreage/localstoreageDataManage';
import { devciesService } from './../../services/device';
import { Component, OnInit } from '@angular/core';

@Component({
    templateUrl: './deliverySchemeSetup.component.html',
    styleUrls: ['./deliverySchemeSetup.component.scss']
})

export class DeliverySchemeSetupComponent implements OnInit {

    private kdsList;
    private selectedKdsItems = [];
    private terminal;
    checkedValues = []
    kdsIds;
    async  ngOnInit() {
        const data = await devciesService.getKDSDevice();
        const existItems = LocalstorageDataManage.current.getValidKDSs();
        this.checkedValues = (existItems && existItems.map(x => x.id)) || [];
        this.selectedKdsItems = existItems;
        this.kdsList = data;
        this.kdsIds = this.kdsList.map(x => {
            return { id: x.id, label: x.name }
        })
        // console.log(this.kdsIds)
    }

    onChange(checkedOptions) {
        this.selectedKdsItems = this.kdsList.filter(kds => checkedOptions.indexOf(kds.id) > -1);
        console.log('selectedKdsItems:',this.selectedKdsItems);
    }

    /**
     * 保存
     */
    save() {
        if (!this.selectedKdsItems || !this.selectedKdsItems.length) {
            MessageBoxService.current.Growl(GrowlMessageType.Warning,'请选择出品台');
            return false;
        }
        LocalstorageDataManage.current.setValidKDSs(this.selectedKdsItems);
        expeditionOrdersService.init();
        NavigateManage.current.navigate(HomePageService.current.getPathByComponentName("home"));
    }
}